﻿using XjjXmm.Message.Service.Model;
using XjjXmm.Message.Service.Subscriber;

namespace XjjXmm.Message.Service;

public interface IBroker
{
    Task Send(Message message);
}

public class BrokerService
{
   private Task<List<ISubscriber>> GetSubscribers(string topic)
    {
        return Task.FromResult(new List<ISubscriber>());
    }

    public async Task Send(Topic topic, Message message)
    {
        var subscribers = await GetSubscribers(topic.Id!);

        foreach (var subscriber in subscribers)
        {
            WorkQueueBroker workQueue =     new WorkQueueBroker(subscriber);
            await workQueue.Send(message);
        }
    }
}



/// <summary>
/// 顺序逐个发送
/// </summary>
public class WorkQueueBroker : IBroker
{
    private readonly ISubscriber subscriber;

    public WorkQueueBroker(ISubscriber subscriber)
    {
        this.subscriber = subscriber;
    }

    public async Task Send(Message message)
    {
       var result = await subscriber.Receive(message.Msg);
    }
}




